﻿package net.sealuitk.gadgets 
{
	import flash.events.MouseEvent;
	import net.sealuitk.UIConst;
	/**
	 * ...
	 * @author mkn
	 */
	public class ButtonSwitch extends Button
	{
		
		public function ButtonSwitch(Name:String, GraphicsMode:String = UIConst.GRAPHICS_FIXED) 
		{
			super(Name, GraphicsMode);
			buildEventListener();
		}
		
		/* ================ Event Listener ================
		 * 
		 */
		
		override protected function buildEventListener():void {
			addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
			addEventListener(MouseEvent.ROLL_OVER, mouseOver);
			addEventListener(MouseEvent.ROLL_OUT, mouseOut);
		}
		
		override protected function mouseDown(e:MouseEvent):void {
			if (state == UIConst.STATE_UP || state == UIConst.STATE_OVER) setTo(UIConst.STATE_DOWN);
			else if (state == UIConst.STATE_DOWN || state == UIConst.STATE_DOWNOVER) setTo(UIConst.STATE_UP);
		}
		
		override protected function mouseOver(e:MouseEvent):void {
			if (state == UIConst.STATE_UP) {
				setTo(UIConst.STATE_OVER);
			} else if (state == UIConst.STATE_DOWN) {
				setTo(UIConst.STATE_DOWNOVER);
			}
		}
		
		override protected function mouseOut(e:MouseEvent):void {
			if (state == UIConst.STATE_OVER) {
				setTo(UIConst.STATE_UP, true, false);
			} else if (state == UIConst.STATE_DOWNOVER) {
				setTo(UIConst.STATE_DOWN, true, false);
			}
		}
	}

}